package ltd.dujiabao.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import ltd.dujiabao.springcloud.entities.CommonResult;
import ltd.dujiabao.springcloud.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : DuJiabao
 * @Project : springcloud
 * @Time : 2021/5/26 21:45
 * @Desc :
 */
@RestController
@Slf4j
public class StorageController {
  @Autowired
  StorageService storageService;

  @PostMapping("/storage/decrease")
  CommonResult decrease(@RequestParam("productId") Long productId, @RequestParam("count") Integer count) {
    int result = storageService.decrease(productId, count);
    if (result > 0)
      return new CommonResult(CommonResult.SUCCESS, "更新库存成功");
    else
      return new CommonResult(CommonResult.FAIlURE, "更新库存失败");
  }
}
